public class QuadSolver {

    // 成员变量，用于存储方程的系数
    private double a;
    private double b;
    private double c;

    // 构造函数，用于初始化方程的系数
    public QuadSolver(double a, double b, double c) {
        if (a == 0) {
            throw new IllegalArgumentException("系数 a 不能为 0");
        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double[] solve() {
        double discriminant = b * b - 4 * a * c;

        if (discriminant > 0)
        {
            // 两个不同的实根
            double root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
            return new double[]{root1, root2};
        }
        else if (discriminant == 0)
        {
            // 一个实根（两个根相等）
            double root = -b / (2 * a);
            return new double[]{root, root};
        }
        else
        {
            // 两个共轭复根
            double realPart = -b / (2 * a);
            double imaginaryPart = Math.sqrt(-discriminant) / (2 * a);
            return new double[]{realPart, imaginaryPart}; // 注意：这里假设复数解的表示方式为[实部, 虚部]
        }
    }
}